/***
This do-file plots the evolution of low-income spending in high workplace rent
ZIP codes.
***/

*-------------------------------------------------------------------------------
* Set up
*-------------------------------------------------------------------------------

* Set $root
project figstabs, root
if (r(buildrunning)==0) include "${root}/code/config_interactive.do"

* Set globals
project, uses("${root}/code/set_globals.do")
include "${root}/code/set_globals.do"
local category "Spending"

* Create required subfolders
cap mkdir "${root}/results/Spending"

*-------------------------------------------------------------------------------
* Load data
*-------------------------------------------------------------------------------
project, uses("${root}/results/Datasets to release/Data - Spending in Low-Income Households in ZIP Codes with High Workplace Rent.csv")
import delimited "${root}/results/Datasets to release/Data - Spending in Low-Income Households in ZIP Codes with High Workplace Rent.csv", clear

gen date = ym(year, month)
format %tm date

*-------------------------------------------------------------------------------
* Plot
*-------------------------------------------------------------------------------

line spend_change_pp date, lcolor(oi2) ///
	xlab(`=ym(2020, 3)' `""Mar" "2020""' ///
	 `=ym(2020, 5)' "May"  ///
	`=ym(2020, 7)' "Jul"  `=ym(2020, 9)' "Sep" ///
	 `=ym(2020, 11)' "Nov"  ///
	`=ym(2021, 1)' `""Jan" "2021""'   `=ym(2021, 3)' "Mar" ///
	 `=ym(2021, 5)' "May"  ///
	`=ym(2021, 7)' "Jul"  `=ym(2021, 9)' "Sep"  `=ym(2021, 11)' "Nov" ///
	, ///
	format(%tm) labsize(3)) xtitle(" ") ///
	ytitle("Change in Consumer Spending (%)" "from January 2020") ///
	ylabel(40 "+40%" 20 "+20%" 0 "0%" -20 "-20%" -40 "-40%", nogrid) ///
	yline(0, lpattern(dash) lcolor(gs8)) ///
	legend(label(1 "High-Workplace Rent ZIPs") size(3) row(1))
	
oi_graph_export "${root}/results/Spending/Spending of Low-Income Households in High Rent ZIPs - replication", type(${fig_type})

* Black and white version for QJE
line spend_change_pp date, lcolor(gs8) ///
	xlab(`=ym(2020, 3)' `""Mar" "2020""' ///
	 `=ym(2020, 5)' "May"  ///
	`=ym(2020, 7)' "Jul"  `=ym(2020, 9)' "Sep" ///
	 `=ym(2020, 11)' "Nov"  ///
	`=ym(2021, 1)' `""Jan" "2021""'   `=ym(2021, 3)' "Mar" ///
	 `=ym(2021, 5)' "May"  ///
	`=ym(2021, 7)' "Jul"  `=ym(2021, 9)' "Sep"  `=ym(2021, 11)' "Nov" ///
	, ///
	format(%tm) labsize(3)) xtitle(" ") ///
	ytitle("Change in Consumer Spending (%)" "from January 2020") ///
	ylabel(40 "+40%" 20 "+20%" 0 "0%" -20 "-20%" -40 "-40%", nogrid) ///
	yline(0, lpattern(dash) lcolor(gs8)) ///
	legend(label(1 "High-Workplace Rent ZIPs") size(3) row(1))

graph export "${root}/results/QJE_Figures_BlackAndWhite/Figure_9d.svg", replace
project, creates("${root}/results/QJE_Figures_BlackAndWhite/Figure_9d.svg")
